home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 12008 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.4 KB  |  95 lines

  1. Path: news.campus.mci.net!usenet
  2. From: Kevin Wilson <kevinw@telis.org>
  3. Newsgroups: comp.lang.c++
  4. Subject: revised derived class question
  5. Date: Sun, 17 Mar 1996 10:17:43 -0800
  6. Organization: MCI State Government and University Systems
  7. Message-ID: <314C5747.19D9@telis.org>
  8. NNTP-Posting-Host: s25-pm02.mtsac.campus.mci.net
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-Mailer: Mozilla 2.0 (Win95; I)
  13.  
  14. Thanks much for the quick reply everybody...
  15.  
  16. Unfortunately I included screwed up listings in my news post... I was too busy trying every 
  17. possible fix I could think of so you got a mish-mash of crap.  Below are correct listings of 
  18. what I was trying to do.
  19.  
  20. The Llist::Retreive function returns a pointer to Llist object, a single entry in the list.
  21.  
  22. Stack::Pop uses Retreive to grab the first object in the list.
  23.  
  24. My compiler gives the following error:
  25. c:\src\cpsc352\hw2\stacklib.cpp(13) : error C2446: '=' : no conversion from 'class ::Llist 
  26. __far *' to 'class ::Stack __far *'
  27.  
  28. It wants a type conversion from Llist to Stack... Not sure how to do that and I didnt think I 
  29. had to for a derived class.
  30. ---------------------------------llist.h-----------------------------------------------
  31. #define NULL    0
  32.  
  33. class Llist{
  34.     private:
  35.         char    *str;        //points to list element
  36.         Llist    *nxt;        //points to next element in list
  37.         static Llist head;    //list head
  38.         static int nvals;   //holds number of elements in list
  39.     public:
  40.                 Llist();
  41.                 Llist(char *x, Llist *ptr);
  42.                 ~Llist();
  43.         int        Insert(char *x, int p);
  44.         int        Locate(char *x);
  45.         Llist    *Retreive(int p);
  46.         int        Delete(int p);
  47.         int        First();
  48.         int        Next(int p);
  49.         int        Previous(int p);
  50.         int        Last();
  51.         int        End();
  52.         int        MakeNull();
  53.         void    PrintList();
  54.         friend    ostream& operator<<(ostream& os, Llist& L); 
  55. };
  56.  
  57. ---------------------------------stack.h----------------------------------------------
  58. //
  59. //    Stack lib using link list class as base
  60. //
  61.  
  62. #include "llist.h"
  63.  
  64. class Stack:public Llist {
  65.     public:
  66.         Stack(void);
  67.         ~Stack();
  68.         Stack    *Pop(void);
  69.         int        Push(char *);
  70. };
  71.  
  72.  
  73. ---------------------------------stacklib.h-------------------------------------------
  74. #include <iostream.h>
  75. #include "stack.h"
  76.  
  77. Stack::Stack():Llist()
  78. {}
  79. Stack::~Stack(){}
  80.  
  81. Stack *Stack::Pop()
  82. {
  83.     Stack *ptr;
  84.  
  85.     ptr = Retreive(1);
  86.     if(ptr != NULL)
  87.         Llist::Delete(1);
  88.     return ptr;
  89. }
  90.  
  91. int Stack::Push(char *x)
  92. {
  93.     return Llist::Insert(x, 1);
  94. }
  95.